package com.zzx.project.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//本项目唯一手动配置类
@Configuration
public class MyConfig implements WebMvcConfigurer {
    //重写视图解析器

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/5xx").setViewName("error/5xx");
        registry.addViewController("/4xx").setViewName("error/4xx");
        //registry.addViewController("/").setViewName("funny");
    }

    //重写资源映射器
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //此处做三个上传路径映射，分别是：Windows idea项目、Windows tomcat8、Linux tomcat9
        registry.addResourceHandler("/userImages/**").addResourceLocations("file:C:/Users/Administrator/IdeaProjects/MyProject/src/main/resources/static/userImages/").addResourceLocations("file:D:/download/apache-tomcat-8.5.50/bin/src/main/resources/static/userImages/").addResourceLocations("file:/opt/apache-tomcat-9.0.31/bin/src/main/resources/static/userImages/");
        registry.addResourceHandler("/articleImg/**").addResourceLocations("file:C:/Users/Administrator/IdeaProjects/MyProject/src/main/resources/static/articleImg/").addResourceLocations("file:D:/download/apache-tomcat-8.5.50/bin/src/main/resources/static/articleImg/").addResourceLocations("file:/opt/apache-tomcat-9.0.31/bin/src/main/resources/static/articleImg/");
    }
}
